from sqlalchemy import Column, Integer, String, JSON
import json
from models import BaseModels


class Roles(BaseModels):
    __tablename__ = 'roles'
    id = Column(Integer, autoincrement=True, primary_key=True, unique=True, nullable=False)
    role = Column(String(32), nullable=False, unique=True, comment="角色")
    describe = Column(String(64), nullable=False, unique=True, comment="角色描述")
    sidebars = Column(JSON, nullable=True, comment="左边栏显示信息")

    def __repr__(self):
        return json.dumps({
            "role_id": self.id,
            "role": self.role,
            "describe": self.describe,
            "sidebars": self.sidebars
        })
